<div id="searchfiltres1">
	<br>
	<table id="m2mfilters">
		<tr>
			<th>Число голосов</th>
			<th>Гарантия производителя</th>
			<th>Количество продаж</th>
			<th>Публиковать</th>
			<th>SEO текст</th>
			<th>Крупногабаритный</th>
			<th>Количество подтоваров</th>
			<th>Страна</th>
			<th>Рекомендуем</th>
		</tr>
		<tr>
			<td><input class='crud_list_filter' type='text' name='search[votes_count]' /></td>
			<td>
				<select class='crud_list_filter' name='search[manufacturer_warranty]'>
					<option value="">Все</option>
					<option value="1">Да</option>
					<option value="0">Нет</option>
				</select>
			</td>
			<td><input class='crud_list_filter' type='text' name='search[sales_count]' /></td>			
			<td>
				<select class='crud_list_filter' name='search[is_active]'>
					<option value="">Все</option>
					<option value="1">Да</option>
					<option value="0">Нет</option>
				</select>
			</td>
			<td><input class='crud_list_filter' type='text' name='search[additional_text]' /></td>
			<td>
				<select class='crud_list_filter' name='search[is_bulky]'>
					<option value="">Все</option>
					<option value="1">Да</option>
					<option value="0">Нет</option>
				</select>
			</td>
			<td><input class='crud_list_filter' type='text' name='search[subproducts_count]' /></td>
			<td>
				<select class='crud_list_filter' name='asearch[country_id]' style="width:100px">
					<option value="">Все</option>
				<?
					$countryRows= CountriesPeer::getInstance()->fetchAll();
					foreach($countryRows as $countryRow){
						echo '<option value="'.$countryRow->getId().'">'.$countryRow->getName().'</option>';
					}
				?>
				</select>
			</td>
			<td>
				<select class='crud_list_filter' name='search[is_recommended]'>
					<option value="">Все</option>
					<option value="1">Да</option>
					<option value="0">Нет</option>
				</select>
			</td>
		</tr>
	</table>
</div>

<div id="searchfiltres2">
	<table id="m2mfilters">
		<tr>			
			<th>Уценка</th>
			<th>Распродажа</th>
			<th>Новинка</th>
			<th>Хит продаж</th>			
			<th>Рейтинг</th>
			<th>Полное описание</th>
			<th>Тэги</th>
			<th>Категории</th>
			<th>Приоритет</th>
			<th>Размер</th>
			<th>Материал</th>
			<th>Габариты</th>
			<th>Цвет</th>
		</tr>
		<tr>	
			
			<td>
				<select class='crud_list_filter' name='search[is_discout]'>
					<option value="">Все</option>
					<option value="1">Да</option>
					<option value="0">Нет</option>
				</select>
			</td>
			<td>
				<select class='crud_list_filter' name='search[is_sale]'>
					<option value="">Все</option>
					<option value="1">Да</option>
					<option value="0">Нет</option>
				</select>
			</td>
			<td>
				<select class='crud_list_filter' name='search[is_new]'>
					<option value="">Все</option>
					<option value="1">Да</option>
					<option value="0">Нет</option>
				</select>
			</td>
			<td>
				<select class='crud_list_filter' name='search[is_hit]'>
					<option value="">Все</option>
					<option value="1">Да</option>
					<option value="0">Нет</option>
				</select>
			</td>
			<td><input class='crud_list_filter' type='text' name='search[rating]' /></td>

			<td><input class='crud_list_filter' type='text' name='search[full_desc]'/></td>

			<td><select class='crud_list_filter' type='text' name='asearch[tag]' style="width:100px">
					<option value="">Все</option>
					<?php
						$table = TagPeer::getInstance();
						$select = $table->select();
						$tag = $table->fetchAll($select);
						foreach($tag as $t){
							echo "<option value='".$t['id']."'>".$t['name']."</option>";
						}
					?>
				</select>

			</td>
			<td><select class='crud_list_filter' type='text' name='asearch[category]' style="width:100px">
					<option value="">Все</option>
					<?php
						$table = ProductCategoryPeer::getInstance();
						$select = $table->select();
						$cat = $table->fetchAll($select);
						foreach($cat as $category){
							echo "<option value='".$category['id']."'>".$category['name']."</option> ";
						} ?>
				</select>

			</td>
			<td><input class='crud_list_filter' type='text' name='search[priority]'>
			<td><input class='crud_list_filter' type='text' name='asearch[size]'>
			<td><input class='crud_list_filter' type='text' name='asearch[material]'>
			<td><input class='crud_list_filter' type='text' name='asearch[dimension]'>
			<td><input class='crud_list_filter' type='text' name='asearch[color]'>
		</tr>
	</table>
	<span id="query_list" onclick="refreshTable()" style="display: block; margin-left: 1100px; background: #EEE; border: 1px solid #CCC; color: #000; font-weight: bold; padding: 5px; margin-bottom: 5px; width: 55px; cursor: pointer;">Выбрать</span>
</div>



<div id='product-export'>
	<div>
		<a href='<?php echo $this->url(array('table' => 'product-export')); ?>'>Выгрузить отчет по товарам</a>
		<br/><br/>
	</div>
</div>

<div id='multiedit_block'>
	<input type='button' id='multiedit' name='multiedit' value='Массовое редактирование' /> <br />
	<input type='button' id='multiedit_selectall' value='Выбрать все' />
	<input type='button' id='multiedit_unselectall' value='Отменить все' />
</div>

<script type='text/javascript'>

function refreshTableCallback()
{
	var $ids = $("#crud_list_items td.item0");
	$ids.each(function() {
		var $td = $(this);
		var $id = $td.text();
		$td.prepend("<input type='checkbox' class='multiId' multiname='ids[]' value='"+$id+"' /> &nbsp; ");
	});
}

$(function() {
	var $crud_list_items = $("#crud_list_items");
	$crud_list_items.before($("#product-export"));
	$crud_list_items.before($("#multiedit_block"));
	$crud_list_items.before($("#searchfiltres1"));
	$crud_list_items.before($("#searchfiltres2"));

	$("#multiedit").live("click", function() {
		$checkboxes = $(".multiId:checked");
		if ($checkboxes.length < 2) {
			alert("Выберите галочками несколько товаров для массового редактирования!");
			return false;
		}
		
		$params = '?';
		$checkboxes.each(function() {
			$params += 'ids[]=' + $(this).val() + '&';
		});

		document.location = '/admin/product/mass' + $params;
	});
	
	
	refreshTableCallback();

	$("#multiedit_selectall").live('click', function() {
		$(".multiId").attr("checked", "checked");
	});

	$("#multiedit_unselectall").live('click', function() {
		$(".multiId").removeAttr("checked");
	});
});
	$(document).ready(function(){
	$("input.crud_list_filter").die('keyup', refreshTable);
	$("select.crud_list_filter").die('change', refreshTable);

	$('input.crud_list_filter').keydown(function(event){
			//alert('sfds');
			switch(event.keyCode)
			{
				case 13:
				refreshTable();
				break;
			}

		});

	$('select.crud_list_filter').keydown(function(event){
			//alert('sfds');
			switch(event.keyCode)
			{
				case 13:
				refreshTable();
				break;
			}

		});
});


</script>

<style type='text/css'>
#multiedit {
	width: 200px;
	height: 50px;
}
</style>